import 'package:dio/dio.dart';
import 'package:mall/core/models/withdraw.dart';
import 'package:mall/core/services/api.dart';
import 'package:mall/core/providers/view_model.dart';

class WithdrawApplyModel extends ViewModel {
  final Api api;

  String _errorMessage;

  WithdrawApplyModel(this.api) : super();

  String get errorMessage => _errorMessage;

  Future<ViewState> withdrawApply(Withdraw withdraw) async {
    viewState = ViewState.busy;
    try {
      await api.withdrawApply(withdraw.id);
      viewState = ViewState.success;
    } catch (e) {
      _errorMessage = e is DioError ? e.message : e.toString();
      viewState = ViewState.error;
    }
    return viewState;
  }
}
